package com.yoga.manager.app.impl;

import com.yoga.common.appexception.AppErrorCodeEnum;
import com.yoga.common.appexception.AppException;
import com.yoga.common.bo.YogaShopBO;
import com.yoga.common.page.PageBO;
import com.yoga.common.qto.YogaShopQTO;
import com.yoga.dao.dao.YogaShopDao;
import com.yoga.manager.app.AppYogaShopManager;
import com.yoga.manager.beanUtil.YogaShopBeanUtil;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by hdx on 2020/10/20.
 */
@Component
public class AppYogaShopManagerImpl implements AppYogaShopManager {

    @Resource
    private YogaShopDao yogaShopDao;

    @Override
    public PageBO<YogaShopBO> findForPage(YogaShopQTO yogaShopQTO) throws AppException {
        PageBO<YogaShopBO> pageBO = new PageBO<>();
        if (yogaShopQTO == null) {
            throw new AppException(AppErrorCodeEnum.PARAMETER_NULL);
        }
        pageBO.setQuery(yogaShopQTO);
        Integer count = yogaShopDao.findForPageCount(yogaShopQTO);
        if (count == null || count <= 0) {
            return pageBO;
        }
        List<YogaShopBO> boList = YogaShopBeanUtil.doList2BOList(yogaShopDao.findForPage(yogaShopQTO));
        pageBO.setTotalCount(count);
        pageBO.setData(boList);

        return pageBO;
    }
}
